// authMiddleware.js
const jwt = require('jsonwebtoken');

const authenticateToken = (req, res, next) => {
  const authHeader = req.headers.authorization;
  console.log(authHeader+"-------------")
  const token = authHeader && authHeader.split(' ')[1];
  console.log(token+"===============")
  if (token == null) return res.sendStatus(401);
  console.log(token+"+++++++++++++++++++")
  jwt.verify(token, '123456', (err, user) => {
    if (err) return res.sendStatus(403);
    req.user = user;
    
    next();
  });
};

module.exports = authenticateToken;